import os
import random


# def getFilePathList(rootDir):
#     filePath_list = []
#     for walk in os.walk(rootDir):
#         part_filePath_list = [os.path.join(walk[0], file) for file in walk[2]]
#         filePath_list.extend(part_filePath_list)
#     return filePath_list
#
# filePath_list = getFilePathList('F:\MyDrivers')
# print(len(filePath_list))

# selected_index = random.sample([10,20,30,40,50], k=3)
# print(selected_index)

import pandas as pd
import numpy as np
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
labelEncoder = LabelEncoder()

y_true=[2,1,0,1,2,0]
y_pred=[2,0,0,1,2,1]
cm = confusion_matrix(y_true,y_pred)
# df = pd.DataFrame(confusion_matrix,columns=labelEncoder.classes_, index=labelEncoder.classes_)
#
# print("shape:\n",df.shape)
# print("info:\n",df.info())
# print("head:\n",df.head())

def plot_confusion_matrix(cm, labels_name, title):
    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    # 归一化
    plt.imshow(cm, interpolation='nearest')    # 在特定的窗口上显示图像
    plt.title(title)# 图像标题
    plt.colorbar()
    num_local = np.array(range(len(labels_name)))
    plt.xticks(num_local, labels_name, rotation=90)    # 将标签印在x轴坐标上
    plt.yticks(num_local, labels_name)    # 将标签印在y轴坐标上
    plt.ylabel('True label')
    plt.xlabel('Predicted label')

plot_confusion_matrix(cm, "label_name", "HAR Confusion Matrix")
plt.savefig('./HAR_cm.png', format='png')
#plt.show()

